<template>
  <div>
    <el-form :model="emailForm" :rules="email" inline label-width="120px">
      <el-form-item label="发件邮箱账号" prop="email_send_account">
        <el-input v-model="emailForm.email_send_account" />
      </el-form-item>
      <el-form-item label="邮箱密码" prop="email_password">
        <el-input v-model="emailForm.email_password" type="password" />
      </el-form-item>
      <el-form-item label="邮箱类型" prop="email_type">
        <el-select v-model="emailForm.email_type">
          <el-option
            v-for="item in emailType"
            :key="item.id"
            :value="item.value"
            :label="item.form_title"
          />
        </el-select>
      </el-form-item>
      <!-- <h3 class="title" style="margin-top:20px"><span /> <b>收件箱设置</b> </h3> -->
      <el-form-item label="收件邮箱账号" prop="email_get_account">
        <el-input v-model="emailForm.email_get_account" />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" class="save" @click="saveEmail">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import systemApi from '@/api/system/system'
export default {
  props: ['data'],
  data() {
    return {
      emailForm: {
        email_get_account: '',
        email_send_account: '',
        email_password: '',
        email_type: '',
        group: this.data.group
      },
      email: {
        email_send_account: [
          { required: 'true', message: '请输入发件箱账号', trigger: 'blur' }
        ],
        email_password: [
          { required: 'true', message: '请输入发件箱密码', trigger: 'blur' }
        ],
        email_type: [
          { required: 'true', message: '请输入发件邮箱类型', trigger: 'blur' }
        ],
        email_get_account: [
          { required: 'true', message: '请输入收件箱账号', trigger: 'blur' }
        ]
      },
      enailData: [],
      emailType: []
    }
  },
  created() {
    this.emailData = this.data.children
    this.emailType = this.data.children[3].children
    this.emailData.forEach(el => {
      this.emailForm[el.title] = el.value
    })
  },
  methods: {
    saveEmail() {
      systemApi.sysUpdate({ ...this.emailForm }).then(res => {
        if (res.code == 0) {
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
